<?php
   class Model_guild extends CI_Model{
		protected $_table = "tbl_guild";
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function getdata($id){
			$this->db->where("id",$id);
			return $this->db->get($this->_table)->row_array();
		}
		public function listall($limit,$start){
			$this->db->limit($limit,$start);
			return $query=$this->db->get($this->_table)->result_array();
		}
		public function listdataByprovide_languaga($provide,$language,$limit,$start){
			$query=$this->db->query("select * from tbl_guild where provide like '%".$provide."%' and language like '%".$language."%' order by id desc limit ".$start.",".$limit);
			return $query->result_array();
		}
		public function add($data){
        	$this->db->insert($this->_table,$data);
		}
		public function del($id){
			$this->db->where("id",$id);
			$this->db->delete($this->_table);
		}
		public function update($data,$id){
			$this->db->where("id",$id);
			$this->db->update($this->_table,$data);
		}
		public function count_search_result(){
			$query=$this->db->query("select count(*) as total from tbl_guild");	
			return $query->row_array();
		}
		public function getpackagebyguildid($idguild){
			$query=$this->db->query("select * from tbl_package where id in (select packageid from tbl_guide_package where guildid=".$idguild.")");
			return $query->result_array();
		}
		public function gettopByprovide_status($provide,$status,$limit,$start){
			$query=$this->db->query("select * from tbl_guild where provide like '%".$provide."%' and status=".$status." order by id limit ".$start.",".$limit);
			return $query->result_array();
		}
		
		//admin
		public function getallbyprovide_name($provide,$name,$language){
			$select="select * from tbl_guild ";
			$order=" order by name ";
			$where=" where 1=1 ";
			if($provide!='0') $where.=" and provide like '%".$provide."%'";
			if($name!='') $where.=" and name like '%".$name."%'";
			if($language!='0') $where.=" and language like '%".$language."%'";
			$query=$this->db->query($select.$where.$order);
			return $query->result_array();
		}
	}